package com.finals.finalsscreen.util;

import java.lang.reflect.Method;

import android.content.Context;
import android.media.AudioManager;
import android.telephony.TelephonyManager;

import com.android.internal.telephony.ITelephony;

public class Util {

	public static final String TAG = "Finals";

	private static ITelephony getITelephony(TelephonyManager telephony) throws Exception {
		Method getITelephonyMethod = telephony.getClass().getDeclaredMethod("getITelephony");
		getITelephonyMethod.setAccessible(true);// 私有化函数也能使用
		return (ITelephony) getITelephonyMethod.invoke(telephony);
	}

	public static void endPhone(Context context) {
		try {
			TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
			ITelephony iTelephony = getITelephony(tm);
			// 挂断电话
			iTelephony.endCall();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public static void MuteRing(Context context) {
		AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		manager.setStreamMute(AudioManager.STREAM_RING, true);
	}

	public static void ReleaseMuteRing(Context context) {
		AudioManager manager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
		manager.setStreamMute(AudioManager.STREAM_RING, false);
	}
}
